#!/bin/bash

groupId=$1
project_name=$2
output=".."

if [ x"$groupId" = x ]; then
	echo "groupId cannot be empty!!!"
	exit
fi

if [ x"$project_name" = x ]; then
	echo "Project name cannot be empty!!!"
	exit
fi

if [ x"$3" != x ]; then
	output=$3
fi

output=${output}/${project_name}

rm -rf ${output}
mkdir ${output}

for d in `ls template`; do
	cp -r template/$d ${output}/$project_name-$d
done

cd ${output}

os=`uname`
if [ "$os" = "Darwin" ]; then
	echo "MACOS"
	sed -i "" "s/groupxxxx/$groupId/g" `grep "groupxxxx" -rl ./*`
	sed -i "" "s/projectxxxx/$project_name/g" `grep "projectxxxx" -rl ./*`
else
	echo "Linux or Windows"
	sed -i "s/groupxxxx/$groupId/g" `grep "groupxxxx" -rl ./*`
	sed -i "s/projectxxxx/$project_name/g" `grep "projectxxxx" -rl ./*`
fi
